var oprate=[
            {"id":"passbtn","value":"审核","color":"blue","func":"detail(this)"},
            {"id":"updbtn","value":"修改","color":"blue","func":"update(this)"},
            {"id":"delbtn","value":"删除","color":"red","func":"del(this)"}];
var requestUrl="../../video/list";
var fileChangeUrl="../../video/frontpic?id=";
datatbody="datatbody";
datathead="datathead";
$(function(){
	search(datatbody,datathead);
});
//详情
function detail(obj){
	var id=$(obj).parent().find("id").html();
	du("../../video/detail","detail",obj,function(json){
		textinit(json.video);
		$("#detail #title").css("font-size","18px");
		$("#detail #videopath").attr("poster","../"+json.video.front_pic);
		$("#detail #videopath").find("source").attr("src","../"+json.video.videopath);
	},function(opo,obtn,flagfunc){
		var status=obtn.id=="pass"?2:0;
		var paramjson={status:status,id:id};
		$.post("../../video/ispass",paramjson,function(data){
			flagfunc(data.flag);
		})
	},325);
}
//修改
function update(obj){
	var id=$(obj).parent().parent().find("id").html();
	du("../../video/detail","update",obj,function(json){
		for(var x in json.video){
			$("#update input[type=text]").each(function(i,item){
				if(item.id==x){
					$("#update #"+item.id).val(json.video[x]);
				}
			});
			$("#update #"+x).each(function(i,item){
				$(item).children().each(function(j,cite){
					$(cite).attr("selected",false);
					if(cite.value!=""&&cite.value==json.video[x]){
						$(cite).attr("selected",true);
					}
				});
			});
		}
		$("#update #description").text(json.video.description);
		$("#update #videopath").find("source").attr("src","../"+json.video.videopath);
		$("#update #videopath").attr("poster","../"+json.video.front_pic);
		$("#update input[type=text]").css("width","80%");
		$("#update #description").css("width","80%");
		$("#update #description").css("height","60px");
		fileChangeUrl=fileChangeUrl+json.video.id;
	},function(opo,obtn,flagfunc){
		var pramjson={};
		pramjson["id"]=id;
		pramjson["description"]=$(opo).find("#description").val();
		pramjson["title"]=$(opo).find("#title").val();
		var frontpic=$(opo).find("video[id=videopath]").attr("poster");
		frontpic=frontpic.substring(frontpic.indexOf("resources"));
		pramjson["front_pic"]=frontpic;
		$.post("../../video/update/save",pramjson,function(data){
			flagfunc(data.flag);
		})
	},325);
}
//删除
function del(obj){
	sure("确认删除吗?",function(){
		var id=$(obj).parent().parent().find("id").html();
		$.post("../../video/delete/"+id,function(data){
			if(data.flag==1){
				msg("操作成功 !",window.parent.document);
			}else{
				msg("操作失败 !",window.parent.document);
			}
			search(datatbody,datathead);
		});
	},window.parent.document,obj);
}